$(document).ready(function() {
    showLogin();
    showBuy();
    signOut();
})
function showLogin() {
    $(".right").click(function() {
        isLogin();
    })
}

function showBuy() {
    $("#buy").hide(),
        $("#image").click(function() {
            $("#buy").show()
        })
    $("#x img").click(function() {
        $("#buy").hide()
    })
    $("#car a").click(function() {
        $("#buy").hide()
    })
}

function isLogin() {
    var login = getCookie("login");
    console.log(login, "222")
        // 判断login里面的cookie
    if (login) {

        loginArr = login.split(",");
        //显示退出按钮
        var username = loginArr[0];
        var userpass = loginArr[1];
        // 得到账号的信息
        $(".tiaozhuan").text(username);
        // 如果有信息让退出显示
        $("#tuichu").toggle({
            display: "block"
        });
        // 如果没有让登录显示
    } else {
        $("#denglu").toggle({
            display: "block"
        });
    }

}

function getCookie(key) {
    let steCookie = document.cookie;
    let arrCookie = steCookie.split("; ");
    for (let i = 0; i < arrCookie.length; i++) {
        let item = arrCookie[i].split("=");
        if (item[0] == key) {
            return item[1];
        }
    }
    return '';
}
// console.log(getCookie("name"));
// 增改
function setCookie(key, value, day) {
    if (day == undefined) {
        document.cookie = `${key}=${value}`;
    } else {
        let date = new Date();
        date.setDate(date.getDate() + day);
        document.cookie = `${key}=${value};expires=` + date;
    }
}
// setCookie("name","小明","7");
// setCookie("id","001");
// 删
function deleteCookie(key) {
    setCookie(key, '', -1);
}

function signOut() {
    $(".tuichu").on("click", function() {
        deleteCookie("login");
        $("#tuichu").hide();
    })
}